package com.controllers;

import com.daos.JobDao;
import com.exceptions.JobNotFoundException;
import com.models.Client;
import com.models.Job;
import com.services.AuthService;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class JobController {

  @Autowired
  private AuthService authentication;

  @Autowired
  private JobDao jobDao;

  public Job getJob(String id) throws JobNotFoundException {
    return jobDao.getJob(id);
  }

  public void saveJob(Job job) {
    jobDao.saveJob(job);
  }

  public Job processJob(String request) throws ParseException {
    Job job = createJob("queued");
    return job;
  }

  private Job createJob(String status) throws ParseException {
    Client owner = authentication.getAuthenticatedUser();
    Job job = new Job(owner, status);
    saveJob(job);
    return job;
  }

}
